package chat.network.http;

import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.whu.zj.MyApplication;
import com.whu.zj.R;
import com.whu.zj.VolleySingleton;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import inter.Delegate;

/**
 * 获取好友
 * Created by Administrator on 2016/3/29.
 */
public class GetAllContacts {

    Delegate delegate;

    String user_ID;

    public void setDelegate(Delegate delegate) {
        this.delegate = delegate;
    }

    public void setUser_ID(String user_ID) {
        this.user_ID = user_ID;
    }

    public void get()
    {
        String IP = MyApplication.share().getResources().getString(R.string.IP);
        String url ="http://"+IP+"/Chat/GetAllContacts";
        StringRequest stringRequest = new StringRequest(Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        if (delegate != null)
                            delegate.onResponse(response);
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (delegate != null)
                    delegate.onErrorResponse(error);
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                map.put("user_ID",user_ID);
                return  map;
            }

            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data,"utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }


    public static class ContactsGroup implements Serializable{
        private String user_ID;
        private String user_NickName;
        private String user_RealName;
        private Boolean user_Status;
        private String user_Group;
        //private long user_GroupNum;

        public String getUser_ID() {
            return user_ID;
        }
        public void setUser_ID(String user_ID) {
            this.user_ID = user_ID;
        }
        public String getUser_RealName() {
            return user_RealName;
        }
        public void setUser_RealName(String user_RealName) {
            this.user_RealName = user_RealName;
        }
        public String getUser_Group() {
            return user_Group;
        }
        public void setUser_Group(String user_Group) {
            this.user_Group = user_Group;
        }
        public String getUser_NickName() {
            return user_NickName;
        }
        public void setUser_NickName(String user_NickName) {
            this.user_NickName = user_NickName;
        }
        public Boolean getUser_Status() {
            return user_Status;
        }
        public void setUser_Status(Boolean user_Status) {
            this.user_Status = user_Status;
        }
//		public long getUser_GroupNum() {
//			return user_GroupNum;
//		}
//		public void setUser_GroupNum(long user_GroupNum) {
//			this.user_GroupNum = user_GroupNum;
//		}
    }

    public static class ResponseContacts {
        private String status;
        private List<ContactsGroup> usersSubs;

        public String getStatus() {
            return status;
        }
        public void setStatus(String status) {
            this.status = status;
        }

        public List<ContactsGroup> getUsersSubs() {
            return usersSubs;
        }
        public void setUsersSubs(List<ContactsGroup> usersSubs) {
            this.usersSubs = usersSubs;
        }
    }
}
